package global;

import java.util.List;

import model.UserInfo;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;

public class IsLogin implements Interceptor {

	@Override
	public void intercept(ActionInvocation arg) {
		Controller me=arg.getController();
		String name=me.getSessionAttr("name");
		String pass=me.getSessionAttr("pass");
		
		List<UserInfo> users =UserInfo.dao.find("select * from userinfo where name=?",name);
		
		UserInfo user;
		if(!users.isEmpty()){
			user=users.get(0);
			if(user.getStr("password").toString().equals(pass)){
				arg.invoke();
			}		
		}else{
			me.setAttr("msg", "错误");
			me.redirect("/login");
		}
		
	}

}
